<template>
  <!-- 街机-扫雷详情 -->
  <el-dialog :modelValue="props.show" custom-class="detailData" :title="GameName(indexStore.gameArray, props.checkedItem.game_id)+$t('46')" :close-on-click-modal="false"
    :close-on-press-escape="false" @close="onHideDetails">
    <div class="border-box" v-loading="data.loading">
      <template v-for="(item, index) in data.filArr" :key="index">
        <div class="flex list">
          <div class="width20">{{ item.label }} </div>
          <span v-if="item.key=='game_id'">
            <div class="gameIcon marginB5">
              <div class="flex marginR5">
                <el-tag size="small">{{ GamePlatform(indexStore.gameArray, props.checkedItem.game_id) }}</el-tag>
                <img class="game-icon" :src="selectToLabel(GAMEICON, props.checkedItem.game_id)" alt="">
              </div>
              {{ selectToLabel(indexStore.gameArray, props.checkedItem.game_id) }}
            </div>
          </span>
          <span v-else-if="item.key == 'win'" :class="+item.value > 0 ? 'colorGre' : 'colorRed'">
            {{ item.value }}</span>
          <span v-else>{{ item.value }}</span>
        </div>
      </template>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, watch } from 'vue'
import { getGameDetailsLog } from '@/api/user'
import { setTimestampTime } from '@/utils/time'
import { BigWan, BigTofixedTwo } from '@/utils/math'
import { GAMEICON } from '@/config/eunm'
import { selectToLabel,GameName,GamePlatform } from '@/utils/index'

import { useStore } from '@/stores/index'
const indexStore = useStore()
import { useI18n } from 'vue-i18n'
const { t } = useI18n()


const props = defineProps({
  checkedItem: Object as any, // 当前条数的数据 
  show: Boolean, // 是否显示
})

interface FilArr {
  label: string,
  value: any,
  key: string
}

const data = reactive({
  filArr: [] as FilArr[],
  loading: false,
})

watch(
  () => [props.checkedItem,props.show],
  async (value) => {
    if (value[0] && value[1]) {
      gameDetails()
    }
  },
)

const gameDetails = async() => {
  try {
    data.loading = true;
    let res = await getGameDetailsLog({
      log_details_id: props.checkedItem.log_details_id,
      game_id: props.checkedItem.game_id
    })
    data.loading = false;
    let obj = res.data
    indexStore.setPageLoading(false)
    data.filArr = [
      { label: t('36'), value: GameName(indexStore.gameArray, props.checkedItem.game_id), key: 'game_id' },
      { label: t('40'), value: props.checkedItem.round_id_str, key: 'round_id_str' },
      { label: t('39'), value: setTimestampTime(props.checkedItem.save_time_stamp), key: 'created_time_stamp' },
      { label: t('348'), value: BigWan(props.checkedItem.bet), key: 'bet' },
      { label: t('349'), value: obj.field_size, key: 'field_size' },
      { label: t('350'), value: obj.select_num, key: 'select_num' },
      { label: t('351'), value: obj.cash_out > 0 ? 0 : obj.select_num, key: 'cash_out' },
      { label: t('352'), value: obj.is_auto == 1 ? '是' : '否', key: 'is_auto' },
      { label: t('353'), value: BigTofixedTwo(obj.x), key: 'x' },
      { label: t('354'), value: BigWan(props.checkedItem.win - props.checkedItem.bet), key: 'win' },
    ]
  } catch (error) {
    data.loading = false;
  }
}

// 重置
const emit = defineEmits(['onHideDetails'])
const onHideDetails = () => {
  emit('onHideDetails', false)
}
</script>
<style scoped lang="scss">
.border-box {
  padding-bottom: 40px;
  font-size: 14px;
  color: var(--text);
}

.fily {
  display: flex;
  flex-wrap: wrap;
  width: 100%;

  .fily-list {
    width: 50%;
  }
}

.flight {
  width: 100%;
}

.list {
  font-weight: bold;
  height: 36px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--el-border-color-lighter);
}
</style>